Shared fault-detection: threshold + status-bit + fault-code enum#486
Draft
mfaferek93 wants to merge 6 commits into
Draft
Shared fault-detection: threshold + status-bit + fault-code enum#486mfaferek93 wants to merge 6 commits into
mfaferek93 wants to merge 6 commits into
Conversation
Introduce ros2_medkit_fault_detection, a header-only evaluator that maps a raw value to faults via three composable modes: numeric threshold, status-word bit decode, and fault-code enum. Migrate the OPC UA plugin's threshold path onto it so it gains bit-decode and enum via new status_bits/fault_enum node-map blocks, with raise/clear edge detection in the shared tracker. Refs #481
The shared FaultTransitionTracker is keyed by fault_code alone, so two detection entries emitting the same code flapped raise/clear every poll cycle. Reject duplicate detection codes at load and extend the event_alarms collision check to status_bits/fault_enum. Decode uint64_t status registers and warn on bit >= 64; README notes unsigned status words. Refs #481
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a shared, protocol-agnostic fault-detection evaluator (ros2_medkit_fault_detection) supporting threshold, status-word bit decode, and fault-code enum mapping, and migrates the OPC UA plugin to use it via new node-map blocks (status_bits, fault_enum) while preserving existing threshold behavior.
Changes:
- Added a new header-only
ros2_medkit_fault_detectionpackage with an evaluator + transition tracker and unit tests. - Updated OPC UA node-map loading and poller evaluation to emit shared fault-detection signals across threshold/status-bit/enum modes, including load-time fault-code collision validation.
- Expanded OPC UA node-map tests and documentation to cover the new detection modes and collision rules.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/ros2_medkit_plugins/ros2_medkit_opcua/test/test_node_map.cpp | Adds tests for parsing and poller-level behavior for threshold/status_bits/fault_enum detection modes and collision cases. |
| src/ros2_medkit_plugins/ros2_medkit_opcua/src/opcua_poller.cpp | Replaces threshold-only alarm evaluation with shared fault-detection evaluation + edge tracking. |
| src/ros2_medkit_plugins/ros2_medkit_opcua/src/opcua_plugin.cpp | Updates alarm callback plumbing to forward shared FaultSignal transitions with entity context. |
| src/ros2_medkit_plugins/ros2_medkit_opcua/src/opcua_client.cpp | Adds uint64_t Variant handling for status-word/enum scenarios. |
| src/ros2_medkit_plugins/ros2_medkit_opcua/src/node_map.cpp | Lowers node-map detection blocks into shared DetectionRule and enforces fault-code uniqueness / event collision checks. |
| src/ros2_medkit_plugins/ros2_medkit_opcua/README.md | Documents new node-map blocks and configuration constraints for shared fault detection. |
| src/ros2_medkit_plugins/ros2_medkit_opcua/package.xml | Adds dependency on ros2_medkit_fault_detection. |
| src/ros2_medkit_plugins/ros2_medkit_opcua/include/ros2_medkit_opcua/opcua_poller.hpp | Updates alarm callback contract and replaces prior per-code state map with shared transition tracker. |
| src/ros2_medkit_plugins/ros2_medkit_opcua/include/ros2_medkit_opcua/opcua_plugin.hpp | Updates fault bridge callback signature to accept shared FaultSignal. |
| src/ros2_medkit_plugins/ros2_medkit_opcua/include/ros2_medkit_opcua/node_map.hpp | Adds shared DetectionRule storage and a detection_entries() accessor. |
| src/ros2_medkit_plugins/ros2_medkit_opcua/CMakeLists.txt | Adds ros2_medkit_fault_detection as a build/test dependency. |
| src/ros2_medkit_fault_detection/test/test_fault_detection.cpp | Adds unit tests covering threshold/status-bit/enum evaluation and transition tracking. |
| src/ros2_medkit_fault_detection/README.md | Documents the shared evaluator API and intended usage by protocol plugins. |
| src/ros2_medkit_fault_detection/package.xml | Declares the new package and its build/test dependencies. |
| src/ros2_medkit_fault_detection/include/ros2_medkit_fault_detection/fault_detection.hpp | Implements the header-only evaluator, rule types, and FaultTransitionTracker. |
| src/ros2_medkit_fault_detection/CMakeLists.txt | Defines the header-only INTERFACE target and test/lint wiring. |
Exclude ament_cmake_clang_format from ament_lint_auto so the explicit ament_clang_format() hook is the only clang_format test (was registered twice, failing configure), and fix its CONFIG_FILE path to the repo root. Add <type_traits> include, make the uint64->int64 reinterpret well-defined via memcpy under C++17, and correct the out-of-range bit README wording. Refs #481
Extend test_alarm_server with writable StatusWord/FaultCode Int32 registers and a set command, and add poll-path bit-decode plus enum-transition scenarios to run_alarm_tests.sh asserting raise/clear via SOVD /api/v1/faults. Refs #481
NaN/inf/uncoercible values now emit no signal, so a transition tracker holds a standing fault instead of a bad read clearing it. Enum decode adds a catch-all for unmapped non-ok codes, status-word decode an optional width mask, and node-map malformed scalars warn not default. Refs #481
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #481
New header-only
ros2_medkit_fault_detectionevaluator with three composable modes (numeric threshold, status-word bit decode, fault-code enum) and an edge-detecting transition tracker. The OPC UA plugin is migrated onto it and gainsstatus_bits/fault_enumnode-map blocks (no threshold regression). Load-time global fault-code uniqueness prevents cross-entry flapping and extends the event_alarms collision check.Tested: 56 unit tests incl. poller-level integration.